var util = require('../../../../utils/util.js');
var api = require('../../../../config/api.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },
  formSubmit: function (e) {
    var warn = "";//弹框时提示的内容
    var flag = true;//判断信息输入是否完整
    var that = this;
    if (e.detail.value.realname == "") {
      warn = "请填写您的姓名！";
    } else if (e.detail.value.mobile == "") {
      warn = "请填写您的手机号！";
    } else if (!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.mobile))) {
      warn = "手机号格式不正确";
    } else if (e.detail.value.idcard == "") {
      warn = "请填写身份证号"
    } else if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(e.detail.value.idcard))) {
      warn = "身份证号格式不正确";
    }  else {
      flag = false;
      wx.showLoading({
        title: '请求中...',
        mask: true,
      });
      util.request(api.UpdataUser, {
        realname: e.detail.value.realname,
        mobile: e.detail.value.mobile,
        idcard: e.detail.value.idcard,
      }, 'POST').then(function (res) {
        if (res.errno === 0) {
          wx.showToast({
            title: '提交成功',
            icon: 'none',
            duration: 2000,
            success: function () {
              setTimeout(function () {
                wx.navigateBack({})
              }, 2000)
            }
          })
        }else{
          wx.showToast({ title: res.msg, icon: 'none', duration: 3000 });
        }
        wx.hideLoading();
      });
    }
    //如果信息填写不完整，弹出输入框
    if (flag == true) {
      wx.showModal({
        title: '提示',
        content: warn
      })
    }
  }
})